package test;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

/**
	@author jkhsieh
	
	Modify and run to add, edit, or delete MySQL records!
	Comment out sections you're not running.
*/
public class SqlExecutor
{
   private String connectionURL = "jdbc:mysql://localhost:3306/mojito?user=root;password=mojito";
   private Connection connection = null;
   private Statement statement = null;
   private ResultSet rs = null;
   private MySqlConsole helper;     //rid redundancy of above?
   
   public SqlExecutor() throws InstantiationException, IllegalAccessException, 
   ClassNotFoundException, SQLException
   {
      Class.forName("com.mysql.jdbc.Driver").newInstance();
      connection = DriverManager.getConnection(connectionURL, "root", "mojito");
      statement = connection.createStatement();
      helper = new MySqlConsole();
   }
   

   public static void main(String[] args) throws InstantiationException, IllegalAccessException, ClassNotFoundException, SQLException
   {
      SqlExecutor exe = new SqlExecutor();
      
      //ADD event......................................................
      
      //field values: modify here
      String eventName = "Event Title";
      int groupID = 0;             //0? if event owner is a user, not group
      String userName = "jkhsieh";  //""? if event owner is a group, not a user
      String startString = "2009-04-30 22:00";
      String endString = "2009-04-30 23:00";
      String description = "notes...";
      boolean recurring = false;
      
      //query -- DO NOT modify
      String query = "INSERT INTO mojito.events VALUES(" + "default,'" + 
         eventName +"',"+ groupID +",'"+ userName +"','"+
         startString +"','"+ endString +"','"+ 
         description + "',"+ recurring + ",'',false,false,false,false,false,false,false"+
      ")";
      System.out.println("query string: " + query);
      exe.statement.executeUpdate(query);
      
      //verify
      exe.helper.showTable("events");
      
      
      //EDIT event......................................................
      eventName = "Picnic";
      
      query = "UPDATE mojito.events SET name='" +  
         eventName +"' WHERE user="+ "'ddeng'";
      System.out.println("query string: " + query);
      exe.statement.executeUpdate(query);
      
      
      //DELETE event......................................................
      
   }

}
